151B - Phone Numbers - CodeForces Solution


implementation strings *1200

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;
int main()
{

  int n;
  cin>>n;
  string s[n];
  int taxi[n]={};
  int pizza[n]={};
  int cafe[n]={};
  for(int i=0;i<n;i++)
  {
      int hey;
      cin>>hey;
      cin>>s[i];
      for(int j=0;j<hey;j++)
      {
          string friendd;
          cin>>friendd;
          int temp1=int(friendd[0])-48;
          int temp2=int(friendd[1])-48;
          int temp3=int(friendd[3])-48;
          int temp4=int(friendd[4])-48;
          int temp5=int(friendd[6])-48;
          int temp6=int(friendd[7])-48;

          if(temp1==temp2&&temp2==temp3&&temp3==temp4&&temp4==temp5&&temp5==temp6)
            taxi[i]++;
          else if(temp1>temp2&&temp2>temp3&&temp3>temp4&&temp4>temp5&&temp5>temp6)
            pizza[i]++;
          else
            cafe[i]++;


      }


  }

   //For taxi


  cout<<"If you want to call a taxi, you should call: ";
  int maxx=*max_element(taxi,taxi+n);
  int flag=0;
  for(int i=0;i<n;i++)
  {
      if(taxi[i]==maxx&&flag==0)
      {


        cout<<s[i];
        flag++;
      }

       else if(taxi[i]==maxx&&flag!=0)
      {
          cout<<", ";


        cout<<s[i];
        flag++;
      }



  }
  cout<<"."<<endl;


  //For pizza


  cout<<"If you want to order a pizza, you should call: ";
  int maxx1=*max_element(pizza,pizza+n);
  int flag1=0;
  for(int i=0;i<n;i++)
  {
      if(pizza[i]==maxx1&&flag1==0)
      {


        cout<<s[i];
        flag1++;
      }

       else if(pizza[i]==maxx1&&flag1!=0)
      {
          cout<<", ";


        cout<<s[i];
        flag1++;
      }



  }
  cout<<"."<<endl;


  //For Cafe


  cout<<"If you want to go to a cafe with a wonderful girl, you should call: ";
  int maxx2=*max_element(cafe,cafe+n);
  int flag2=0;
  for(int i=0;i<n;i++)
  {
      if(cafe[i]==maxx2&&flag2==0)
      {


        cout<<s[i];
        flag2++;
      }

       else if(cafe[i]==maxx2&&flag2!=0)
      {
          cout<<", ";


        cout<<s[i];
        flag2++;
      }



  }
  cout<<"."<<endl;







}


Comments

Submit
0 Comments
More Questions

450. Delete Node in a BST
445. Add Two Numbers II
442. Find All Duplicates in an Array
437. Path Sum III
436. Find Right Interval
435. Non-overlapping Intervals
406. Queue Reconstruction by Height
380. Insert Delete GetRandom O(1)
332. Reconstruct Itinerary
368. Largest Divisible Subset
377. Combination Sum IV
322. Coin Change
307. Range Sum Query - Mutable
287. Find the Duplicate Number
279. Perfect Squares
275. H-Index II
274. H-Index
260. Single Number III
240. Search a 2D Matrix II
238. Product of Array Except Self
229. Majority Element II
222. Count Complete Tree Nodes
215. Kth Largest Element in an Array
198. House Robber
153. Find Minimum in Rotated Sorted Array
150. Evaluate Reverse Polish Notation
144. Binary Tree Preorder Traversal
137. Single Number II
130. Surrounded Regions
129. Sum Root to Leaf Numbers